package com.group3.customer.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	private static String drivenClassName = "oracle.jdbc.OracleDriver";
	private static String url = "jdbc:oracle:thin:@zha-ita078-w7:1521:xe";
	private static String username = "amc";
	private static String password = "amc";
	
	static {
		try {
			Class.forName(drivenClassName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn =  DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void free(Connection conn, PreparedStatement ps, ResultSet rs) {
		try {
			if(rs != null) {
				rs.close();	
			}
			if(ps != null) {
				ps.close();
			}
			if(conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			// TODO: handle exception
		}
	}
}
